package com.dobbinsoft.iotechn.data.config.oss;

import com.aliyun.oss.OSSClient;
import com.dobbinsoft.iotechn.data.client.AliyunObjectStorageClient;
import com.dobbinsoft.iotechn.data.client.ObjectStorageClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: rize
 * Date: 2019/12/15
 * Time: 17:21
 */
@Configuration
@ConditionalOnProperty("oss.aliyun.oss.endpoint")
public class OSSDataConfig {

    @Value("${oss.aliyun.oss.accessId}")
    private String accessId;
    @Value("${oss.aliyun.oss.accessKey}")
    private String accessKey;
    @Value("${oss.aliyun.oss.endpoint}")
    private String endpoint;
    @Value("${oss.aliyun.oss.bucket}")
    private String bucket;
    @Value("${oss.aliyun.oss.dir}")
    private String dir;
    @Value("${oss.aliyun.oss.callbackUrl}")
    private String callbackUrl;

    @Bean
    public OSSClient ossClient() {
        return new OSSClient(endpoint, accessId, accessKey);
    }

    @Bean
    public ObjectStorageClient objectStorageClient() {
        return new AliyunObjectStorageClient();
    }

}
